package com.qasystem.qa.core.common;

import com.qasystem.qa.core.base.BaseEnum;
import lombok.Getter;

import java.io.Serializable;
@Getter
public class ResultBean<T> implements Serializable {
    private ResultBean() {}
    private Integer code;
    private String message;

    private T data;
    public ResultBean<String> ok() {
        return ok("");
    }
    public static <B> ResultBean<B> ok(B data) {
        ResultBean<B> result = new ResultBean<>();
        result.code = ResultCode.OK;
        result.message = "操作成功";
        result.data = data;
        return result;
    }
    public static ResultBean<String> error() {
        return error("操作失败");
    }

    public static ResultBean<String> error(String message) {
        ResultBean<String> result = new ResultBean<>();
        result.code = ResultCode.ERROR;
        result.message = message;
        return result;
    }
    private static class ResultCode {
        /** 操作成功 */
        private static final Integer OK = 200;
        /** 操作失败 */
        private static final Integer ERROR = 500;
        /** 用户未登陆/信息有误，需要重新登陆 */
        private static final Integer UNLOGIN = 403;
    }
}
